package com.salim.leetcode.$187;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class RepeatedDNASequences {
    public List<String> findRepeatedDnaSequences(String s) {
        if(s.length()<10){
            return new ArrayList<>();
        }
        HashMap<String,Integer> countMap = new HashMap<>();
        List<String> result = new ArrayList<>();
        String key;
        for(int i=0;i+9<s.length();i++){
            key = s.substring(i,i+10);
            if(countMap.containsKey(key)){
                if(countMap.get(key)==0){
                    result.add(key);
                    countMap.put(key,1);
                }
            }else{
                countMap.put(key,0);
            }
        }
        return result;
    }
}
